<?
include("session.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../webkit/grid/import.js"></script>
<script type="text/javascript" src="../webkit/dialog/import.js"></script>
<script type="text/javascript" src="./common.js"></script>
<link type="text/css" rel="stylesheet" href="page.css"/>
</head>
<body>


<table width=100% height=100% cellspacing=0 cellpadding=0>
	<tr bgcolor="#eeeeee">
	<form name=f>
	<td height=30>&nbsp;
	定单状态：<select id="order_status"><option value=''>-请选择-</option><option value='1'>等待受理</option><option value='2'>正在备货</option><option value='3'>已经发货</option><option value='4'>完成购物</option><option value='5'>申请取消</option><option value='-1'>确认取消</option></select>　
    客户手机：<input type=text id='mobile' size=12>　定单号：<input type=text id='order_no' size=12>　
	<input type="button" value="查询" onclick="search()">　　　　　　
	<img src="images/14.png"> 系统消息： <span id="message_tips"><font color=gray>暂无定单消息提醒！</font></span> <iframe src='about:blank' width=1 height=0 frameborder=0 id="message_voice"></iframe>
	</td>
	</tr>
	<tr>
	<td>
		<table id="flex1" style="display:none"></table>
	</td>
	</form>
	</tr>
</table>


<script type="text/javascript">
	<?if($_SESSION['user_flag'] == "admin") {?>
	var h = parent.document.body.clientHeight-(115+102);
	<?} else {?>
	var h = parent.document.body.clientHeight-(115+76);
	<?}?>
	if(h < 0) h = 'auto'
	$("#flex1").flexigrid({
		url: 'order_query.php?action=list',
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'a', width : 40, sortable : false, align: 'center'},
			{display: '商品名', name : 'a', width : 80, sortable : false, align: 'center'},
			{display: '金额', name : 'total', width : 40, sortable : true, align: 'center'},
			{display: '类型', name : 'type', width : 40, sortable : true, align: 'center'},
			{display: '单价', name : 'price', width : 40, sortable : true, align: 'center'},
			{display: '包装', name : 'box', width : 50, sortable : true, align: 'center'},
			{display: '顾客名称', name : 'a', width : 60, sortable : false, align: 'center'},
			{display: '联系电话', name : 'a', width : 80, sortable : false, align: 'center'},
			{display: '区域', name : 'area', width : 50, sortable : true, align: 'center'},
			{display: '收货地址', name : 'a', width : 120, sortable : false, align: 'center'},
			{display: '定单时间', name : 'a', width : 120, sortable : false, align: 'center'},
			{display: '评分', name : 'a', width : 40, sortable : false, align: 'center'},
			{display: '来源', name : 'a', width : 50, sortable : false, align: 'center'},
			{display: '备注', name : 'a', width : 100, sortable : false, align: 'center'},
			{display: '定单状态', name : 'a', width : 60, sortable : false, align: 'center'},
			{display: '操作', name : 'a', width : 160, sortable : false, align: 'center'}
			],
		buttons : [
            {name: '新增', bclass: 'add', onpress : add},    
			{name: '修改', bclass: 'edit', onpress : edit}  
			<?if($_SESSION['crm_user_flag'] == "admin") {?>
			,{name: '删除', bclass: 'del', onpress : del}
			<?}?>
		],
		
		async : true,
		usepager: true,
		title: '定单管理',
		useRp: true,
		rp: 15,
		showTableToggleBtn: false,
		width: 'auto',
		height: h,
		resizable : false,
		singleSelect : true,
		onSuccess : function() {show_sum_total("2,")}	
	});

    
    $('#flex1').dblclick( function (e) { 
        select_row_on_dblclick(e);
        edit();
    }); 

   
	<?
	$add_url = "order_panel.php?op=add";
	$edit_url = "order_panel.php?op=edit&id=";
	$del_url = "order_query.php?action=del&id=";
	$dlg_size = "600,360";
	require("grid_common_js.php");
	?>

	function calc() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			alert("请选择一条有效记录！");
			return false;
		}
		if(confirm("确认要生成结算单吗?")) {
			$.get("money_query.php?action=calc&client_id="+id, function(data){
				if(data == "ok") {
					alert("操作成功！")
				} else {
					alert(data);	
				}
			});
		}
	}

	function search() { 
		var url = "order_query.php?action=list";
        if($("#order_status").val()!="") {
            url += "&order_status="+ $("#order_status").val();
        }      
        if($("#mobile").val()!="") {
            url += "&mobile="+ $("#mobile").val();
        } 
         if($("#order_no").val()!="") {
            url += "&order_no="+ $("#order_no").val();
        }        
		$('#flex1').flexOptions({'url': url}).flexReload(); 
	}

	function set_order_status(id, status) {
		if(confirm('确认要进行此操作吗？')) {
			$.get("order_query.php?action=set_order_status&id="+id+"&status="+status, function(data) {
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				}
			});
		}
	}

	function do_callback(id, truename, mobile) {
		if(confirm('确认要对顾客[ '+truename+' ]进行回访操作吗？')) {
			$.get("order_query.php?action=do_callback&mobile="+mobile+"&id="+id, function(data) {
				if(data == "ok") {
					alert("回访操作成功，请稍后查看客户的评价！");
				}
			});
		}
	}
	
	function cancel_order(id) {
		dlg = new Dialog({ title: '申请取消定单', resizable:false, maximizable:false}).href("cancel_order.php?order_id="+id);
		dlg.show().setSize(400, 180).center();
	}

	<? if($_SESSION['crm_uid'] != '400') {?>
	window.setInterval("check_new_order()", 1000*15);
	<? } ?>

	function check_new_order() {
		$.get("order_query.php?action=check_order_message", function(data) {
			//alert(data);
			eval("var obj = "+data);
			if(obj['new_order_count'] >0 || obj['cancel_order_count'] >0) {
				$("#message_voice").attr("src", "play_new_message.php");
			}
			var html = "";
			if(obj['new_order_count'] > 0 ) {
				html += "<b style='color:green'> 有 <font color=blue>"+ obj['new_order_count'] +"&nbsp;</font>条新的定单！</b>";
			}
			if(obj['cancel_order_count'] > 0 ) {
				html += "<b style='color:green'>有 <font color=red>"+ obj['cancel_order_count'] +"</font>&nbsp;条申请取消的定单！</b>";
			}
			if(html == "") {
				html = "<font color='gray'>暂无定单消息提醒！</font>"
			}
			$("#message_tips").html(html);
		});
	}

</script>
</body>
</html>
